package com.wangsd.web.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangsd.web.coupon.entity.MiniMenuConfig;
import com.wangsd.web.coupon.mapper.MiniMenuConfigMapper;
import com.wangsd.web.coupon.service.MiniMenuConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author generator
 * @since 2020-01-02
 */
@Service
public class MiniMenuConfigServiceImpl extends ServiceImpl<MiniMenuConfigMapper, MiniMenuConfig> implements MiniMenuConfigService {
    @Resource
    MiniMenuConfigMapper miniMenuConfigMapper;

    @Override
    public IPage<MiniMenuConfig> selectPage(Integer pageNum, Integer pageSize, MiniMenuConfig config) {
        Page<MiniMenuConfig> page = new Page<>(pageNum, pageSize);
        IPage<MiniMenuConfig> resultIPage = miniMenuConfigMapper.selectListXml(page, config);
        return resultIPage;
    }

    @Override
    public void addOrUpdate(MiniMenuConfig entity) {
        if (entity.getId() != null) {
            miniMenuConfigMapper.updateById(entity);
        } else {
            miniMenuConfigMapper.insert(entity);
        }
    }

    @Override
    public List<MiniMenuConfig> selectConfigListByCompanyId(Long companyId) {
        QueryWrapper<MiniMenuConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id", companyId);
        queryWrapper.orderByDesc("config_order");
        List<MiniMenuConfig> configCompanies = miniMenuConfigMapper.selectList(queryWrapper);
        return configCompanies;
    }
}
